<head>
  <style> body { margin: 0; } </style>

  <script src="//unpkg.com/3d-force-graph"></script>
  <script src="https://unpkg.com/neo4j-driver"></script>
  <!--<script src="../../dist/3d-force-graph.js"></script>-->
</head>

<body>
  <div id="3d-graph"></div>

  <script>
    const driver = neo4j.driver("bolt://demo.neo4jlabs.com", neo4j.auth.basic("gameofthrones", "gameofthrones"),{encrypted: true});
    const Graph = ForceGraph3D()(document.getElementById('3d-graph')).graphData({ nodes: [], links: []});

	const session = driver.session({database:"gameofthrones"});
	const start = new Date()
    session
      .run('MATCH (n) WITH n MATCH (n)-->(m) RETURN id(n) as source, id(m) as target LIMIT $limit', {limit: neo4j.int(5000)})
      .then(function (result) {
         result.records.forEach(r => { 
	       const { nodes, links } = Graph.graphData();
           const link={source:r.get('source').toNumber(), target:r.get('target').toNumber()}
           Graph.graphData({
                nodes: [...nodes, { id:link.source }, { id: link.target}],
                links: [...links, link]
            });
        });        
        session.close();
        console.log(Graph.graphData().links.length+" links loaded in "+(new Date()-start)+" ms.")
      })
      .catch(function (error) {
        console.log(error);
      });
  </script>
</body>